package com.psg.controller;

import com.psg.pojo.Produce;
import com.psg.pojo.User;
import com.psg.service.impl.ProduceServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping()
public class IndexController {

    @Autowired
    private ProduceServiceImpl produceService;

    @RequestMapping({"/","/index"})
    private ModelAndView toIndex(ModelAndView mav, HttpSession session){
        User login = (User) session.getAttribute("login");
        System.out.println("login:"+login);
        List<Produce> all = produceService.findAll();
        mav.addObject("productList",all);
        if (login!=null){
            mav.addObject("login",login);
        }
//        mav.setViewName("shop_message");
//        mav.setViewName("address");
//        mav.setViewName("car");
//        mav.setViewName("order");
//        mav.setViewName("readmoreShop");
//        mav.setViewName("shop");
//        mav.setViewName("header");
//        mav.setViewName("customer  ");
        mav.setViewName("index");
        return mav;
    }

}
